class Person implements Comparable {
    static hasMany = [companies:Company, outOfOffice:OutOfOffice]
    static belongsTo = [Company, User]

    /** The user associated with this person if any */
//    User user
    /** The Persons Title */
    Title title
    /** Person's First Name*/
    String firstName
    /** Person's Last Name*/
    String lastName
    /** Person's Phone */
    String phone
    /** Person's Email */
    String email
    /** Person's Notes */
    String notes

    static constraints = {
        title(nullable:true)
        firstName(nullable:false, blank:false)
        lastName(nullable:true, blank:true)
        phone(nullable:true, phoneNumber:true)
        email(nullable:true, email:true)
        notes(nullable:true, maxSize:2048)
    }

    int compareTo(obj) {
        def thisName = firstName + lastName
        def objName = obj.firstName + obj.lastName
        thisName.compareTo(objName)
    }

    def getName() {
        "${firstName} ${lastName}"
    }

    String toString() {
        String str
        if (firstName) {
            str = "${firstName} ${lastName?:""} ${title?:""}"
        } else {
            str = "No Name"
        }
        return str
    }
}
